const EssayModel = require('../do/models/essay'),
      Type = require('../do/models/type')
class EssayService {
    async getEssay(data){
        const tid = data;
        if(!tid){
            return await await EssayModel.findAll({include:{
                association:
                EssayModel.belongsTo(Type, {foreignKey:'typeid'})
             }}
            );
        }
        return  await EssayModel.findOne({
            where:{
                
            },
            include:{
            association:
            EssayModel.belongsTo(Type, {foreignKey:'typeid'})
         }}
        );
   
        
       
  
       
    }
    async createEssay(data){
        return await EssayModel.create({data});
    }
    async destroyEssay(id){
        return await EssayModel.destroy({
            where:{
                id
            }
        })
        
    }
    async updateEssay(id,data){
        return await EssayModel.update({
            data
        },{
            where:{
                id
            }
        })
    }
    async changeEssayStatus(id,status){
        return await EssayModel.update({
            status
        },{
            where:{
                id
            }
        })
    }
} 
module.exports = new EssayService();